﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2011
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/
package evideo.display.application 
{
    import graphics.display.Background;
    import graphics.geom.EdgeMetrics;
    
    /**
     * The main body of the application.
     */
    public class Body extends Background 
    {
        /**
         * Creates a new Body instance.
         */
        public function Body()
        {
            //
        }
        
        /**
         * The offset of the body when is resized.
         */
        public var border:EdgeMetrics = new EdgeMetrics(0,0,0,0) ;
        
        /**
         * Invoked when the display is updated.
         */
        protected override function viewChanged():void
        {
            x = 0 ;
            y = 0 ;
            if ( stage != null )
            {
                var $w:Number = stage.stageWidth  ;
                var $h:Number = stage.stageHeight ;
                if ( border != null )
                {
                    $w -= ( border.left + border.right   ) ;
                    $h -= ( border.top  + border.bottom  ) ;
                }
                x += ( $w - w ) / 2 ;
                x = x > 0 ? x : 0 ;
                
                y += ( $h - h ) / 2 ;
                y = y > 0 ? y : 0 ;
            }
        }
    }
}
